package com.ruoyi.whole.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.whole.domain.DmsWholeSalesReturn;
import com.ruoyi.whole.service.IDmsWholeSalesReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 退车管理Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/whole/return")
public class DmsWholeSalesReturnController extends BaseController
{
    @Autowired
    private IDmsWholeSalesReturnService dmsWholeSalesReturnService;

    /**
     * 查询退车管理列表
     */
    @PreAuthorize("@ss.hasPermi('whole:return:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsWholeSalesReturn dmsWholeSalesReturn)
    {
        startPage();
        List<DmsWholeSalesReturn> list = dmsWholeSalesReturnService.selectDmsWholeSalesReturnList(dmsWholeSalesReturn);
        return getDataTable(list);
    }

    /**
     * 导出退车管理列表
     */
    @PreAuthorize("@ss.hasPermi('whole:return:export')")
    @Log(title = "退车管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsWholeSalesReturn dmsWholeSalesReturn)
    {
        List<DmsWholeSalesReturn> list = dmsWholeSalesReturnService.selectDmsWholeSalesReturnList(dmsWholeSalesReturn);
        ExcelUtil<DmsWholeSalesReturn> util = new ExcelUtil<DmsWholeSalesReturn>(DmsWholeSalesReturn.class);
        util.exportExcel(response, list, "退车管理数据");
    }

    /**
     * 获取退车管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:return:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsWholeSalesReturnService.selectDmsWholeSalesReturnById(id));
    }

    /**
     * 新增退车管理
     */
    @PreAuthorize("@ss.hasPermi('whole:return:add')")
    @Log(title = "退车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsWholeSalesReturn dmsWholeSalesReturn)
    {
        return toAjax(dmsWholeSalesReturnService.insertDmsWholeSalesReturn(dmsWholeSalesReturn));
    }

    /**
     * 修改退车管理
     */
    @PreAuthorize("@ss.hasPermi('whole:return:edit')")
    @Log(title = "退车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsWholeSalesReturn dmsWholeSalesReturn)
    {
        return toAjax(dmsWholeSalesReturnService.updateDmsWholeSalesReturn(dmsWholeSalesReturn));
    }

    /**
     * 删除退车管理
     */
    @PreAuthorize("@ss.hasPermi('whole:return:remove')")
    @Log(title = "退车管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsWholeSalesReturnService.deleteDmsWholeSalesReturnByIds(ids));
    }

    /**
     * 删除退车管理
     */
    @PreAuthorize("@ss.hasPermi('whole:return:edit')")
    @Log(title = "退车结算", businessType = BusinessType.DELETE)
    @GetMapping("/returnAccount/{ids}")
    public AjaxResult returnAccount(@PathVariable Long[] ids)
    {
        return toAjax(dmsWholeSalesReturnService.returnAccountByIds(ids));
    }
}
